<template>
	<view class="uni_box">
		<!-- #ifdef APP-PLUS -->
		<!-- <view class="immerse"></view> -->
		<!-- #endif -->
		<view class="content">
			<!-- <u-sticky :offset-top="BarHeight()" h5-nav-height="44"> -->
				<view class="tabview">
					<u-tabs :list="tablist" :is-scroll="false" :current="tabcurrent" @change="tabchange" active-color="#E8433A" inactive-color="#CCCCCC"></u-tabs>
				</view>
			<!-- </u-sticky> -->
			<view class="list">
				<view class="tilist-jiaocai">
					<view class="tiitem-two" v-for="(item,index) in list" :key="index" @click="listClick(item)">
						<image :src="item.image" class="itemimg" mode=""></image>
						<view class="itembot">
							<text class="tbiao txt">{{ item.title }}</text>
							<text class="timiao">课程购买时间：{{item.createtime}} 至：{{ item.endtime }}</text>
							<view class="linview">
								<view class="xue xues">{{item.button_text}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			

			<!-- 底部弹出 -->
			<view class="botpop">
				<u-popup v-model="botshow" mode="bottom" @close="botshow=false">
					<view class="popview">
						<view class="shaiview">
							<view class="shaiitem">
								<text class="shaitit">科目</text>
								<view class="shailist">
									<view class="shais" :class="cate_info.id==item.id?'sactive':''" v-for="(item,index) in cate_data" :key="index" @click="getkeClick(item)">{{ item.name }}</view>
								</view>
							</view>
							<view class="shaiitem">
								<text class="shaitit">级别</text>
								<view class="shailist">
									<view class="shais" :class="level_info.id==item.id?'sactive':''" v-for="(item,index) in level_data" :key="index"  @click="getjiClick(item)">{{ item.name }}</view>
								</view>
							</view>
							<view class="chongview">
								<view class="czhi" @click="botshow=false">重置</view>
								<view class="que" @click="getpopbtn">确认</view>
							</view>
						</view>
					</view>
				</u-popup>
			</view>
		</view>
		<!-- 底部导航 -->
		<Tabbar :current="2"></Tabbar>
</view>
</template>

<script>
export default {
	data() {
		return {
			swlist: [{
						image: '/static/banner.png',
					},
					{
						image: '/static/banner.png',
					},
					{
						image: 'https://cdn.uviewui.com/uview/swiper/3.jpg',
					}
				],
				tablist:[
					// {
					// 	name: '正在学'
					// }, {
					// 	name: '待激活'
					// }, {
					// 	name: '已过期'
					// },{
					// 	name:'已失效'
					// }
				],
				tabcurrent:0,
				isshai:false,
				botshow:false,
				type_id:'',
				list: [],
				page: 1,
				limit: 10,
				last_page: 1,
				status: "loadmore",

				cate_id:'1',//科目id
				level_id:'0',//级别id
				cate_data:[],
				cate_info:{
					id:'',
					name:''
				},
				level_data:[],
				level_info:{
					id:''
				},
		}
	},
	components: {
	},
	computed: {
	},

	mounted() {

	},
	async onLoad() {
		this.getfgetMyComboType();//课程状态
	},
	async onShow() {
	},
	onReachBottom: function () {
		this.loadmore();
	},
	methods: {
		async getfgetMyComboType(){
			let res = await this.$u.api.getMyComboType({
			});
			let tablist = []
			let shuju = res
			for(let i in shuju){
				let a ={}
				a.name = shuju[i]
				a.id = i
				tablist.push(a)
			}
			// console.log(tablist)
			this.tablist = tablist
			this.type_id = this.tablist[0].id
			this.getkemu();//获取科目
			
		},
		async getList(){
			let res = await this.$u.api.getMyComboList({
				page:this.page,
				type_id:this.type_id,
				cate_id:this.cate_info.id,
				level_id:this.level_info.id
			});
			this.last_page = res.lastpage;
			let list = res.list;
			this.list = this.page == 1 ? list : [...this.list, ...list];	
			if(this.page >= this.last_page){
				this.status = 'nomore';
			}
		},
		getClear(){
			this.list = []
			this.page = 1,
			this.status= "loadmore"
			this.getList()
		},
		getpopbtn(){
			this.botshow = false
			this.getClear()
		},
		async getkemu(){
			let res = await this.$u.api.usergetCateList({
			});
			this.cate_data = res
			this.cate_info = res[0]
			this.getjibie();//级别
		},	
		async getjibie(){
			let res = await this.$u.api.usergetLevelList({
				cate_id:this.cate_info.id
			});
			this.level_data = res
			this.level_info = res[0]
			this.getList();
		},	
		getkeClick(item){
			this.cate_info = item
			this.getjibie();//级别
		},
		getjiClick(item){
			this.level_info = item
		},
		loadmore() {
			let page = this.page;
			// let last_page = this.last_page;
			if (this.status == 'loadmore') {
				this.page++;
				this.getList();
			}
		},
		tabchange(e){
			this.tabcurrent = e
			this.type_id = this.tablist[e].id
			this.getClear()
		},
		listClick(item){
			this.toPage(item)
		}
	}
}
</script>

<style lang="scss" scoped>

page{
	background-color: #fff;
}
.content{
	background-color: #fff;
	// padding-bottom: 150rpx;
	.tabview{
		padding: 40rpx;
		background-color: #fff;
		z-index: 100;
		// margin-top:  calc(var(--window-top));
	}
	.xuanview{
		height: 88rpx;
		position: relative;
		display: flex;
		flex-direction: row;
		border-top: 1rpx solid #eee;
		background-color: #fff;
		z-index: 100;
		.xuanitem{
			width: 50%;
			height: 100%;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			.qtit{
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #111111;
			}
			.xia{
				width: 11rpx;
				height: 6rpx;
				margin-left: 10rpx;
			}
			.xias{
				width: 11rpx;
				height: 6rpx;
				margin-left: 10rpx;
				display: none;
			}
		}
		.xactive{
			.qtit{
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #FA4E4E;
				
			}
			.xia{
				width: 11rpx;
				height: 6rpx;
				margin-left: 10rpx;
				display: none;
			}
			.xias{
				width: 11rpx;
				height: 6rpx;
				margin-left: 10rpx;
				display: inline-block;
			}
		}
	}
	

	.list{
		padding: 0 30rpx;
	}
	.tilist-jiaocai{
	// margin-top: 40rpx;
	.tiitem-two{
		display: flex;
		flex-direction: row;
		background: #FFFFFF;
		border-radius: 10rpx;
		// padding: 20rpx;
		padding: 0rpx 0 39rpx;
		margin-bottom: 39rpx;
		border-bottom: 1rpx solid #eee;
		.itemimg{
			width: 275rpx;
			height: 179rpx;
			background: #F8F8F8;
			border-radius: 10rpx;
			margin-right: 20rpx;
		}
		.itembot{
			flex: 1;
			display: flex;
			flex-direction: column;
			.tbiao{
				max-width: 100%;
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #111111;
				display: inline-block;
			}
			.timiao{
				font-weight: 500;
				font-size: 20rpx;
				color: #999999;
				margin-top: 20rpx;
				margin-bottom: 10rpx;
				display: inline-block;
			}

			.linview{
				display: flex;
				margin-top: auto;
				flex-direction: row;
				align-items: center;
				.xue{
					padding: 7rpx 15rpx;
					background: #999999;
					border-radius: 30rpx;
					font-weight: 500;
					font-size: 24rpx;
					color: #FFFFFF;
				}
				.xues{
					background: linear-gradient(-90deg, #FA4E4E, #FD894F);
					color: #fff;
				}
				.jine{
					font-family: DIN;
					font-weight: bold;
					font-size: 20rpx;
					color: #FA4E4E;
					.jinnum{
						font-size: 32rpx;
					}
					
				}
				.mian{
					margin-left: auto;
					font-weight: 500;
					font-size: 20rpx;
					color: #CCCCCC;
				}
			}
		}
	}
}
}
.hright{
	position: absolute;
	right: 10px;
	display: flex;
	flex-direction: row;
	align-items: center;
	.xiaicon{
		width: 15rpx;
		height: 8rpx;
	}
	text{
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 30rpx;
		color: #060606;
		display: inline-block;
		margin-right: 15rpx;
	}
}
// 底部弹窗
.botpop{
	/deep/.u-drawer-bottom{
		background-color: transparent;
	}
	.popview{
		padding: 30rpx 0;
		background-color: #fff;
		border-radius: 40rpx 40rpx 0 0;
	}
	.shaiview{
		padding: 25rpx 30rpx;
		// background-color: #fff;
		display: flex;
		flex-direction: column;
		position: relative;
		width: 100%;
		// z-index: 100;
		.shaiitem{
			margin-bottom: 20rpx;
			.shaitit{
				display: block;
				margin-bottom: 24rpx;
				font-family: PingFangSC;
				font-weight: bold;
				font-size: 24rpx;
				color: #333333;
			}
			.shailist{
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				.shais{
					width: 31%;
					margin-right: 2%;
					height: 64rpx;
					background: #F8F8F8;
					border-radius: 32rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					margin-bottom: 25rpx;
					font-weight: 500;
					font-size: 22rpx;
					color: #333333;
				}
				.sactive{
					background: #FFF0F0;
					color: #FA4E4E;
				}
			}
		}
		.shaiitem:last-child{
			margin-bottom: 0 !important;
		}
		
		.chongview{
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;
			.czhi{
				width: 48%;
				height: 80rpx;
				background: #F8F8F8;
				border-radius: 40rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #111111;
			}
			.que{
				width: 48%;
				height: 80rpx;
				background: linear-gradient(-90deg, #FA4E4E, #FD894F);
				border-radius: 40rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #fff;
			}
		}
	}

}
</style>
